<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
//        return $this->view->fetch();
    }

    public function signature($customer_id = '')
    {

        $customer = Db::name('customer')->where(['customer_id' => $customer_id])->find();
        if (!$customer || !file_exists($customer->contract_url)) {
            echo "文件不存在";
            die;
        }
//        $this->assign('file_url', $file_url);
        $this->assign('customer_id', $customer_id);
        $this->assign('customer', $customer);
        return $this->view->fetch();
    }

    public function details($customer_id = '')
    {
        $model = new \app\admin\model\customer\Intention;
        $customer = $model->where(['id' => $customer_id])->find();
        if (!$customer || !file_exists($customer->contract_url)) {
            echo "文件不存在";
            die;
        }
        $this->assign('customer_id', $customer_id);
        $this->assign('customer', $customer);
        return $this->view->fetch();
    }

    public function saveImage($image, $customer_id)
    {
        $signature_url = saveBase64($image);
        $model = new \app\admin\model\customer\Intention;
        $model->where(['id' => $customer_id])
            ->update(['signature_url' => $signature_url]);
        (new \app\admin\model\customer\Intention)->saveCustomerContract($customer_id);
        return $this->success('提交成功');
    }

}
